package socket;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 聊天室客户端；
 */
public class Client01 {
    private Socket socket;

    public Client01() {
        //创建连接
        try {
            System.out.println("客户端等待连接...");
            socket = new Socket("localhost",8089);
            System.out.println("客户端连接连接成功。");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public void start(){
        //流的写出
        try {
            OutputStream os = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os);
            BufferedWriter br = new BufferedWriter(osw);
            PrintWriter pw = new PrintWriter(br,true);

            String str  ;
            Scanner scan = new Scanner(System.in);
            while ( !"exit".equalsIgnoreCase(str = scan.nextLine())){
                pw.println(str);
            }


        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    public static void main(String[] args) {
        Client01 client = new Client01();
        client.start();
    }


}

